/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.caro.gui;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.caro.utils.Constants;

/**
 *
 * @author PhucAnh
 */
public class MenuGui extends javax.swing.JFrame implements ActionListener {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * Creates new form MenuInterface
     */
	private static MenuGui menuGui = null;
	public static MenuGui getInstance(){
		if (menuGui == null) menuGui = new MenuGui();
		return menuGui;
		
	}
    private MenuGui() {
        initComponents();
        setLocationRelativeTo(null);
        singlePlayerButton.addActionListener(this);
        multiPlayerButton.addActionListener(this);
        settingButton.addActionListener(this);
        aboutButton.addActionListener(this);
        exitButton.addActionListener(this);
    }

    public JButton getAboutButton() {
        return aboutButton;
    }

    public void setAboutButton(JButton aboutButton) {
        this.aboutButton = aboutButton;
    }

    public JButton getExitButton() {
        return exitButton;
    }

    public void setExitButton(JButton exitButton) {
        this.exitButton = exitButton;
    }

    public JButton getMultiPlayerButton() {
        return multiPlayerButton;
    }

    public void setMultiPlayerButton(JButton multiPlayerButton) {
        this.multiPlayerButton = multiPlayerButton;
    }

    public JButton getSettingButton() {
        return settingButton;
    }

    public void setSettingButton(JButton settingButton) {
        this.settingButton = settingButton;
    }

    public JButton getSinglePlayerButton() {
        return singlePlayerButton;
    }

    public void setSinglePlayerButton(JButton singlePlayerButton) {
        this.singlePlayerButton = singlePlayerButton;
    }
   
    private void initComponents() {

    	try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
        jLabel1 = new javax.swing.JLabel();
        singlePlayerButton = new javax.swing.JButton();
        multiPlayerButton = new javax.swing.JButton();
        settingButton = new javax.swing.JButton();
        aboutButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 26)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("CARO CHESS");

        singlePlayerButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        singlePlayerButton.setForeground(new java.awt.Color(0, 0, 255));
        singlePlayerButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/caro/resource/_single8.png"))); // NOI18N
        singlePlayerButton.setText("Single Player");

        multiPlayerButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        multiPlayerButton.setForeground(new java.awt.Color(0, 0, 255));
        multiPlayerButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/caro/resource/_suite8.png"))); // NOI18N
        multiPlayerButton.setText("Multiplayer  ");

        settingButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        settingButton.setForeground(new java.awt.Color(0, 0, 255));
        settingButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/caro/resource/hammer-icon.png"))); // NOI18N
        settingButton.setText("Setting     ");

        aboutButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        aboutButton.setForeground(new java.awt.Color(0, 0, 255));
        aboutButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/caro/resource/alert.image_icon_info.png"))); // NOI18N
        aboutButton.setText("About     ");

        exitButton.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        exitButton.setForeground(new java.awt.Color(0, 0, 255));
        exitButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/caro/resource/Exit_22.png"))); // NOI18N
        exitButton.setText("  Exit        ");

        jLabel2.setText("ver 1.12.136");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(131, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(101, 101, 101))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(multiPlayerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(singlePlayerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(settingButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(aboutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(127, 127, 127))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24))))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {aboutButton, exitButton, multiPlayerButton, settingButton, singlePlayerButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1)
                .addGap(27, 27, 27)
                .addComponent(singlePlayerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(multiPlayerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19)
                .addComponent(settingButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(aboutButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(exitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
        setVisible(true);
    }
    
    
    private javax.swing.JButton aboutButton;
    private javax.swing.JButton exitButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton multiPlayerButton;
    private javax.swing.JButton settingButton;
    private javax.swing.JButton singlePlayerButton;
   
    
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == singlePlayerButton){
			try {
				new MainGame(Constants.AI_MODE, null);
				
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		else if (e.getSource() == multiPlayerButton){
			new WaitingRoom();
		}
		this.setVisible(false);
	}
}
